package cn.xutongxue.doc.controller;

import cn.xutongxue.common.entity.ResponseResult;
import cn.xutongxue.doc.module.dto.DocUploadRequestDto;
import cn.xutongxue.doc.module.vo.DocVo;
import cn.xutongxue.doc.service.DocService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/doc")
@RequiredArgsConstructor
public class DocController {

    private final DocService docService;

    @PostMapping("/upload")
    public ResponseResult<DocVo> uploadDoc(@RequestPart("file") MultipartFile multipartFile,
                                           DocUploadRequestDto docUploadRequestDto,
                                           HttpServletRequest httpServletRequest) {
        DocVo docVo = docService.uploadDoc(multipartFile, httpServletRequest, docUploadRequestDto);
        return ResponseResult.success(docVo);
    }
}
